import React from 'react';
const GetCapcha =(props) =>{
    this.state = {
        count: 60, // 秒数初始化为60秒
        liked: true // 文案默认为‘获取验证码‘
      }
    handleClick = () => {
        // liked is false 的时候，不允许再点击
        if (!this.state.liked) {
          return
         }
        let count = this.state.count
        console.log(count)
        const timer = setInterval(() => {
          this.setState({ 
             count: (count--)
             }, () => {
             if (count === 0) {
               clearInterval(timer);
               this.setState({
                 liked: true ,
                 count: 60
               })
             }
          });
        }, 1000);
     }
    return(
        <p onClick={this.handleClick}>
          {
            this.state.liked 
            ? 
            <span>获取验证码</span>
            : 
            <span className="count_second">{this.state.count + 's'}</span> 
          }
        </p>
    )
}

export default GetCapcha;